#include "stm32f4xx_hal.h"
#include "steer.h"

extern TIM_HandleTypeDef htim1;

#define OPEN_DUTY 2450
#define CLOSE_DUTY 1100
//#define OPEN_DUTY 1110
//#define CLOSE_DUTY 2600

void steer_init(void)
{
    HAL_TIM_Base_Start(&htim1);

    HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);
    HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_4);
}

void steer_cover_ctrl(uint8_t mode)
{
    if(mode == 0){
        __HAL_TIM_SetCompare(&htim1, TIM_CHANNEL_2, OPEN_DUTY);
    }
    else{
        __HAL_TIM_SetCompare(&htim1, TIM_CHANNEL_2, CLOSE_DUTY);
    }
}

void steer_safety_ctrl(void)
{
        __HAL_TIM_SetCompare(&htim1, TIM_CHANNEL_4, CLOSE_DUTY);
}
